{template '_header'}
<style type="text/css">
    .multi-img-details .multi-item img{height:100px;}
    .table > thead > tr > th,
    .table > tbody > tr > th,
    .table > tfoot > tr > th,
    .table > thead > tr > td,
    .table > tbody > tr > td,
    .table > tfoot > tr > td {
        border-top: none;
    }.refund-group{display: none;}
</style>
<div class="page-header">

    当前位置：<span class="text-primary"> {if !empty($item['id'])}编辑{else}添加{/if}商品 <small>{if !empty($item['id'])}修改【{$item['titles']}】{/if}</small></span>
</div>

<div class="page-content">
    <div class="page-sub-toolbar">
         <span class=''>
            {ifp 'sale.fullback.add'}
                <a class='btn btn-primary btn-sm' href="{php echo webUrl('sale/fullback/add')}"><i class='fa fa-plus'></i> 添加商品</a>
            {/if}
        </span>
    </div>
    <form {ife 'sale.fullback' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$item['id']}" />
    <div class="tab-content ">
        <div class="tab-pane active">
            <div class="panel-body">

                <div class="form-group">
                    <label class="col-lg control-label">排序</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'sale.fullback' $item}
                        <input type='text' class='form-control' name='displayorder' value="{$item['displayorder']}" />
                        <span class="help-block">数字越大，排名越靠前,如果为空，默认排序方式为创建时间</span>
                        {else}
                        <div class='form-control-static'>{$item['displayorder']}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg control-label must">商品标题</label>
                    <div class="col-sm-9 col-xs-12 ">
                        {ife 'sale.fullback' $item}
                        <input type="text" id='titles' name="titles" class="form-control" value="{$item['titles']}" data-rule-required="true"/>
                        {else}
                        <div class='form-control-static'>{$item['titles']}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg control-label">全返类型</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'sale.fullback' $item}
                        <label class="radio-inline">
                            <input type="radio" name="type" value="0" {if empty($item['type']) || $item['type'] == 0}checked="true"{/if}  />
                            指定金额
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="type" value="1"  {if $item['type'] == 1}checked="true"{/if} />
                            金额比例
                        </label>
                        {else}
                        <div class='form-control-static'>
                            {if $item['type'] == 0}
                            指定金额
                            {elseif $item['type']==1}
                            金额比例
                            {/if}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg control-label must">选择商品</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'sale.fullback' $item}
                            {if empty($item)}
                            <div>
                                <?php echo tpl_selector_new('goodsid',array('preview'=>true,
                                'readonly'=>true,
                                'required'=>true,
                                'type'=>'fullback',
                                'value'=>$item['title'],
                                'url'=>webUrl('sale/fullback/query'),
                                'optionurl'=>'sale.fullback.hasoption',
                                'items'=>$item,
                                'nokeywords'=>1,
                                'autosearch'=>1,
                                'buttontext'=>'选择商品',
                                'placeholder'=>'请选择商品')
                                )
                                ?>
                            </div>
                            {else}
                                <div class="">
                                    <input type="text" id="goodsid_text" name="goodsid_text" value="{$item['title']}" class="form-control text valid" readonly="" data-rule-required="true" aria-required="true" aria-invalid="false" aria-describedby="goodsid_text-error">
                                </div>
                                <div class="input-group multi-audio-details container">
                                    <table class="table">
                                        <thead>
                                        <tr>
                                            <th style='width:80px;'>商品名称</th>
                                            <th style='width:220px;'></th>
                                            <th>全返金额</th>
                                        </tr>
                                        </thead>
                                        <tbody id="param-items" class="ui-sortable">
                                        {if !empty($item)}
                                        <tr class="multi-product-item" data-id="{$item['goodsid']}">
                                            <input type="hidden" class="form-control img-textname" readonly="" value="{$item['title']}">
                                            <input type="hidden" value="{$item['goodsid']}" name="goodsid[]">
                                            <td style="width:80px;">
                                                <img src="{php echo tomedia($item['thumb'])}" style="width:70px;border:1px solid #ccc;padding:1px">
                                            </td>
                                            <td style="width:220px;">{$item['title']}</td>
                                            <td>
                                                {if $item['hasoption']>0}
                                                    <a class="btn btn-default btn-sm" data-toggle="ajaxModal"
                                                       href="{php echo webUrl('sale/fullback/hasoption',array('goodsid'=>$item['goodsid'],'id'=>$item['id']))}" id="optiontitle{$item['goodsid']}">&yen;{php echo price_format($item['minallfullbackallprice'],2)} ~ &yen;{php echo price_format($item['maxallfullbackallprice'],2)}</a>
                                                    <input type="hidden" id="fullbackgoods{$item['goodsid']}" value="{$optionid}" name="fullbackgoods[{$item['goodsid']}]">
                                                    {loop $item['option'] $op}
                                                        <input type="hidden" value="{$op['allfullbackprice']},{$op['fullbackprice']},{$op['allfullbackratio']},{$op['fullbackratio']},{$op['day']}" name="fullbackgoodsoption{$op['id']}">
                                                    {/loop}
                                                {else}
                                                <a class="btn btn-default btn-sm" data-toggle="ajaxModal"
                                                   href="{php echo webUrl('sale/fullback/hasoption',array('goodsid'=>$item['goodsid'],'id'=>$item['id']))}" id="optiontitle{$item['goodsid']}">&yen;{php echo price_format($item['minallfullbackallprice'],2)}</a>
                                                <input type="hidden" id="fullbackgoods{$item['goodsid']}" value="" name="fullbackgoods[{$item['goodsid']}]">
                                                <input type="hidden" value="{$item['minallfullbackallprice']},{$item['fullbackprice']},{$item['minallfullbackallratio']},{$item['fullbackratio']},{$item['day']}" name="goods{$item['goodsid']}">
                                                {/if}
                                            </td>
                                        </tr>
                                        {/if}
                                        </tbody>
                                    </table>
                                </div>
                            {/if}
                        {else}
                        {if !empty($item)}
                        <table class="table">
                            <thead>
                            <tr>
                                <th style='width:80px;'>商品名称</th>
                                <th style='width:220px;'></th>
                                <th>全返金额</th>
                            </tr>
                            </thead>
                            <tbody id="param-items" class="ui-sortable">
                            {if !empty($item)}
                            <tr class="multi-product-item" data-id="{$item['goodsid']}">
                                <input type="hidden" class="form-control img-textname" readonly="" value="{$item['title']}">
                                <input type="hidden" value="{$item['goodsid']}" name="goodsid[]">
                                <td style="width:80px;">
                                    <img src="{php echo tomedia($item['thumb'])}" style="width:70px;border:1px solid #ccc;padding:1px">
                                </td>
                                <td style="width:220px;">{$item['title']}</td>
                                <td>
                                    {if $item['hasoption']>0}
                                        <a class="btn btn-default btn-sm" data-toggle="ajaxModal"
                                           href="javascript:void(0);" id="optiontitle{$item['goodsid']}">&yen;{php echo price_format($item['minallfullbackallprice'],2)} ~ &yen;{php echo price_format($item['maxallfullbackallprice'],2)}</a>
                                        <input type="hidden" id="fullbackgoods{$item['goodsid']}" value="{$optionid}" name="fullbackgoods[{$item['goodsid']}]">
                                        {loop $item['option'] $op}
                                        <input type="hidden" value="{$op['allfullbackprice']},{$op['fullbackprice']},{$op['allfullbackratio']},{$op['fullbackratio']},{$op['day']}" name="fullbackgoodsoption{$op['id']}">
                                        {/loop}
                                    {else}
                                        <a class="btn btn-default btn-sm" data-toggle="ajaxModal"
                                           href="javascript:void(0);" id="optiontitle{$item['goodsid']}">&yen;{php echo price_format($item['minallfullbackallprice'],2)}</a>
                                        <input type="hidden" id="fullbackgoods{$item['goodsid']}" value="" name="fullbackgoods[{$item['goodsid']}]">
                                        <input type="hidden" value="{$item['minallfullbackallprice']},{$item['fullbackprice']},{$item['minallfullbackallratio']},{$item['fullbackratio']},{$item['day']}" name="goods{$item['goodsid']}">
                                    {/if}
                                </td>
                            </tr>
                            {/if}
                            </tbody>
                        </table>
                        {else}
                        暂无商品
                        {/if}
                        {/if}
                    </div>
                </div>

                <div class="form-group cgt cgt-3">
                    <label class="col-lg control-label">全返时间</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'sale.fullback' $item}
                        <div class="input-group fixsingle-input-group">
                            <span class="input-group-addon">确认收货</span>
                            <input type="number" class="form-control" name="startday" value="{$item['startday']}">
                            <span class="input-group-addon">天后，开始全返</span>
                        </div>
                        <span class="help-block">全返的时间尽量设置超过系统允许【确认收货】->【申请退款】的时间</span>
                        {else}
                        <div class='form-control-static'>确认收货：{$coupon['startday']}天后，开始全返</div>
                        {/if}
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-lg control-label">全返开始后支持退款</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'sale.fullback' $item}
                        <label class="radio-inline">
                            <input type="radio" name="refund" value="1"  {if $item['refund'] == 1}checked="true"{/if} />
                            是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="refund" value="0" {if empty($item['refund']) || $item['refund'] == 0}checked="true"{/if}  />
                            否
                        </label>
                        <div class="input-group refund-group-click {if $item['refund'] == 0}refund-group{/if}" style="padding-top:10px;">
                            <div class="alert alert-danger">
                                如果您选择全返商品支持退款，会员在全返开始后发起【退款】请求，可退款金额将减去已返金额，已返金额不会退款；如果全返金额大于商品实际价格，不能退款。
                            </div>
                        </div>
                        {else}
                        <div class='form-control-static'>
                            {if $item['refund'] == 0}
                            不支持退款
                            {elseif $item['refund']==1}
                            支持退款
                            {/if}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group">
                    <label class=" col-lg control-label">状态</label>
                    <div class="col-xs-12 col-sm-9">
                        <div class="input-group">
                            {ife 'sale.fullback' $item}
                            <label class="radio radio-inline">
                                <input type="radio" name="status" value="1" {if intval($item['status']) ==1 }checked="checked"{/if}> 开启
                            </label>
                            <label class="radio radio-inline">
                                <input type="radio" name="status" value="0" {if intval($item['status']) ==0}checked="checked"{/if}> 关闭
                            </label>
                            {else}
                            <div class='form-control-static'>{if intval($item['status']) ==1 }开启{else}关闭{/if}</div>
                            {/if}
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </div>

    {ife 'sale.fullback' $item}
    <div class="form-group">
        <label class="col-lg control-label"></label>
        <div class="col-sm-9 col-xs-12">
            <input type="submit"  value="提交" class="btn btn-primary" />
            <a class="btn btn-default" href="{php echo webUrl('sale/fullback')}">返回列表</a>
        </div>
    </div>
    {/if}

    </form>
</div>
<script>
    $(function () {
        $(":radio[name=refund]").off("click").on("click",function () {
            if($(this).val()==1){
                $(".refund-group-click").show();
            }else{
                $(".refund-group-click").hide();
            }
        })
    })
</script>
{template '_footer'}